package com.chima.dao;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.chima.domain.AddWork;
public class AddWorkDao extends HibernateDaoSupport{
	
	//分页查询
			public List< AddWork> findByCriteria(DetachedCriteria criteria, int firstResult,int maxResults) {
				return this.getHibernateTemplate().findByCriteria(criteria,firstResult,maxResults);
			}
		   //查找总页数
			public int findByTotalCount() {
				List list= this.getHibernateTemplate().find("select count(*) from AddWork");
				long temp = (Long) list.get(0);
				return (int) temp;
			}
			public void save(AddWork addWork) {
				this.getHibernateTemplate().save(addWork);
			}
			public void update(AddWork addWork) {
				this.getHibernateTemplate().update(addWork);
				
			}
			
			public void delete(int id) {
				this.getHibernateTemplate().delete(this.getHibernateTemplate().load(AddWork.class, id));
			}
			public  AddWork findById(int id) {
				Session session=this.getSession();
				AddWork a = (AddWork) session.createQuery("from AddWork where id=?").setParameter(0, id).uniqueResult();
				super.releaseSession(session);
				return  a;
			}

}
